<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                <td>项目名称</td>
                <td><input type="date" v-model="querinfo.times"></td>
            </tr>
            <tr>
                <td>图片</td>
                <td><input type="file" @change="imgs">
                <img :src="querinfo.phone" alt="" width="50" height="50" v-if="querinfo.phone!=''">
                </td>
            </tr>
            <tr>
                <td>喜欢</td>
                <td><input type="checkbox" name="like" v-model="querinfo.likes" value="足球">足球
                    <input type="checkbox" name="like" v-model="querinfo.likes" value="篮球">篮球
                    <input type="checkbox" name="like" v-model="querinfo.likes" value="乒乓球">乒乓球
                    
                </td>
            </tr>
            
            
            <tr>
                <td>状态</td>
                <td><input type="radio" name="state" :value="1" v-model="querinfo.state">启用
                <input type="radio" name="state" :value="0" v-model="querinfo.state">禁用</td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" @click="ok" value="添加"></td>
            </tr>
            </tbody>
            
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';

import { ref,reactive } from 'vue';
import { useRoute ,useRouter} from 'vue-router';
const router=useRouter();
const route=useRoute();
let querinfo:any=reactive({

  "times": "",
  "phone": "",
  "likes": [],
  "state": "",
 
})
const imgs=(e:any)=>{
    var obj=e.target.files[0];
    let f=new FormData();
    f.append("file",obj)
    axios({
        url:'/api/Imgs/Imgs',
        method:'post',
        data:f
    })
    .then(res=>{
        querinfo.phone=res.data
    })
}


const ok=()=>{
    querinfo.likes=querinfo.likes.toString();
    axios({
        url:'/api/House/AddHouse',
        method:'post',
        data:querinfo
    })
    .then(res=>{
        
     if(res.data>=0)
    {
        alert("添加成功");
        return;
    }
    else
    {
        alert("添加失败");
        return;
    }
    })
}

</script>

<style scoped>

</style>